package son.nt.act2;

import son.nt.R;
import son.nt.util.LogUtil;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemLongClickListener;
  /** 
   * 
   * @author sonnt
   * 2012.09.13
   * to show COntext menu when long click item
   *
   */
public class ContextMenuActivity extends ListActivity implements OnItemLongClickListener{
	private ListView listView = null;
	private ArrayAdapter<String>adapter = null;
	private Context mContext = null;
	private final static String names[] = {
		"Son",
		"Huyen",
		"Thanh Minh",
		"Hoang Minh",
		"Thi Thu",
		"Khanh Ly",
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mContext = this;
		listView = getListView();
		adapter = new ArrayAdapter<String>(mContext	, android.R.layout.simple_list_item_1,names);
		listView.setAdapter(adapter);
		listView.setOnItemLongClickListener(this);
	}
	public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		registerForContextMenu(listView);
		return false;
	}
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		// TODO Auto-generated method stub
		super.onCreateContextMenu(menu, v, menuInfo);
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.act2_context_menu, menu);
	}
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.edit:
			LogUtil.toast(mContext, "edit");break;
		case R.id.delete:
			LogUtil.toast(mContext, "delete");break;

		default:
			break;
		}
		return super.onContextItemSelected(item);
	}
}
